package com.sk.action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.sk.dao.OrderDao;

public class SeachAction extends HttpServlet {

	OrderDao prodao=new OrderDao();
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String method = request.getParameter("method");
		if ("seach".equals(method)) {
			seach(request,response);
		} else if ("all".equals(method)) {
		   all(request,response);
		 
		}else if("seach2".equals(method)){
			seach2(request,response);
			
		}else if("seach3".equals(method)){
			seach3(request,response);
			
			
		}
		
	
	}
	
	private void all(HttpServletRequest request, HttpServletResponse response)
	throws UnsupportedEncodingException, ServletException, IOException {
		 // List<ProductBean> prolist=prodao.getAllProduct();
		  
			//request.setAttribute("prolist", prolist);
			request.getRequestDispatcher("pages/listseach.jsp").forward(request, response);
	          
	}
	

	private void seach2(HttpServletRequest request, HttpServletResponse response)
			throws UnsupportedEncodingException, ServletException, IOException {
		
			String brandname=new String(request.getParameter("brand").getBytes("ISO-8859-1"),"gbk");
	System.out.println(brandname);
//	//List<ProductBean> problist=prodao.getbybrand(brandname);
//	
//	//if(problist.size()!=0){
//
//			request.setAttribute("prolist", problist);
//			request.getRequestDispatcher("pages/listseach.jsp").forward(request, response);
//	
//	}else{
//		 request.getRequestDispatcher("pages/noseach.jsp").forward(request, response);
//		
//		
//	}
//		  
		
		
		
	}
	
	
	

	private void seach(HttpServletRequest request, HttpServletResponse response)
			throws UnsupportedEncodingException, ServletException, IOException {
		
//		
//		String proname=new String(request.getParameter("ji").getBytes("ISO-8859-1"),"gbk");
//		//	List<ProductBean> problist=prodao.getbyname(proname);
//			if(problist.size()!=0){
//				
//		
//					request.setAttribute("prolist", problist);
//					request.getRequestDispatcher("pages/listseach.jsp").forward(request, response);
//			
//			}else{
//				 request.getRequestDispatcher("pages/noseach.jsp").forward(request, response);
//				
//				
//			}
}

	

	private void seach3(HttpServletRequest request, HttpServletResponse response)
			throws UnsupportedEncodingException, ServletException, IOException {
		
		
		String kai=new String(request.getParameter("kai").getBytes("ISO-8859-1"),"gbk");
	

		String shu=new String(request.getParameter("shu").getBytes("ISO-8859-1"),"gbk");
		
////			List<ProductBean> problist=prodao.getbyprice(kai, shu);
//			if(problist.size()!=0){
//
//					request.setAttribute("prolist", problist);
//					request.getRequestDispatcher("pages/listseach.jsp").forward(request, response);
//			
//			}else{
//				 request.getRequestDispatcher("pages/noseach.jsp").forward(request, response);
//				
//				
//			}
	}
	
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

}
